From: Colin Walters Date: Thu, 12 Jan 2017 15:02:23 +0000 (-0500) Subject: trivial-httpd: Daemonize better X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~4^2~41^2~14 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=2a71afc50779f2b0cd13ea48762af348c396ad2b;p=ostree.git trivial-httpd: Daemonize better I was trying to debug `test-pull-c`, and typing `Ctrl-C` in gdb ended up sending `SIGINT` to trivial-httpd as well, killing it. Daemonize a bit more properly to avoid this. I also followed the standard `/dev/null` guidelines. Closes: #643 Approved by: jlebon --- diff --git a/src/ostree/ostree-trivial-httpd.c b/src/ostree/ostree-trivial-httpd.c index ef297af6..ddcb2fc0 100644 --- a/src/ostree/ostree-trivial-httpd.c +++ b/src/ostree/ostree-trivial-httpd.c @@ -30,6 +30,7 @@ #include "otutil.h" #include +#include #include #include #include @@ -597,9 +598,12 @@ run (int argc, char **argv, GCancellable *cancellable, GError **error) goto out; } /* Child, continue */ + if (setsid () < 0) + err (1, "setsid"); /* Daemonising: close stdout/stderr so $() et al work on us */ - fclose (stdout); - fclose (stdin); + freopen("/dev/null", "r", stdin); + freopen("/dev/null", "w", stdout); + freopen("/dev/null", "w", stderr); } else {